let fs = require("fs");
const size = 3;

function copy(src, target) {
  fs.open(src, 'r', 0o666, function(err, fd) {
    fs.open(target, 'a', 0o666, function(err, writeFd) {
      let buff = Buffer.alloc(size);
      ! function next() {
        fs.read(fd, buff, 0, size, null, function(err, byte, buffer) {
          if (byte > 0) {
            //递归执行
            fs.write(writeFd, buff, 0, byte, null, next)
          }
        })
      }()
    })
  })
}
copy('6.fs/2.txt', '6.fs/copy.txt')
fs.close(); //关闭文件
//强行的把缓存区的数据写入文件,并且关闭
fs.fsync(fd, function(err) {
  fs.close()
})